package com.ssy.lingxi.product.entity.customer;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ssy.lingxi.product.entity.platform.AttributeValue;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;

/**
 * 属性值实体类--平台后台
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/23
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_customer_attribute_value", indexes = {@Index(name = "product_customer_attribute_value_member_id_member_role_id_idx", columnList = "memberId,memberRoleId"),
        @Index(name = "product_customer_attribute_value_value_idx", columnList = "value"),
        @Index(name = "product_customer_attribute_value_is_enable_idx", columnList = "isEnable")})
public class CustomerAttributeValue implements Serializable {
    private static final long serialVersionUID = -7210333335632444841L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="customer_attribute_value_seq")
    @SequenceGenerator(sequenceName="product_customer_attribute_value_seq", name="customer_attribute_value_seq",allocationSize = 1)
    private Long id;

    /**
     * 属性值
     */
    @NotEmpty(message = "属性值不能为空")
    @Column(columnDefinition = "varchar(60)", nullable = false)
    private String value;

    /**
     * 属性值图片url路径
     */
    @Column(columnDefinition = "varchar(250)")
    private String imageUrl;

    /**
     * 属性值是否有效
     */
    @Column(columnDefinition = "boolean", nullable = false)
    private Boolean isEnable = true;

    /**
     * 会员id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberId;

    /**
     * 会员名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberName;

    /**
     * 会员角色id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long memberRoleId;

    /**
     * 会员角色名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String memberRoleName;

    /**
     * 用户id
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long userId;

    /**
     * 用户名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String userName;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();

    /**
     * 会员属性实体
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="customerAttributeId",referencedColumnName = "id")
    private CustomerAttribute customerAttribute;

    /**
     * 后台属性值实体
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="attributeValueId",referencedColumnName = "id")
    private AttributeValue attributeValue;

}
